package io.unicorn.modules.water.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.Query;

import io.unicorn.modules.water.dao.ProDataDao;
import io.unicorn.modules.water.entity.ProDataEntity;
import io.unicorn.modules.water.service.ProDataService;


@Service("proDataService")
public class ProDataServiceImpl extends ServiceImpl<ProDataDao, ProDataEntity> implements ProDataService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProDataEntity> page = this.page(
                new Query<ProDataEntity>().getPage(params),
                new QueryWrapper<ProDataEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getDataByProcedure(Map<String, Object> params) {
        Integer pageSize = (Integer.parseInt(params.get("limit").toString()));
        Integer currPage = (Integer.parseInt(params.get("page").toString()));

        //System.out.print(params.toString());

        List<ProDataEntity> dataList = baseMapper.execProData(params);
        //从第几条数据开始
        Integer firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        Integer lastIndex = currPage * pageSize;

        lastIndex = lastIndex > dataList.size() ? dataList.size() : lastIndex;

        return new PageUtils(dataList.subList(firstIndex, lastIndex),dataList.size(),pageSize,currPage);
    }

    @Override
    public PageUtils getDataByProcedureNb(Map<String, Object> params) {
        Integer pageSize = (Integer.parseInt(params.get("limit").toString()));
        Integer currPage = (Integer.parseInt(params.get("page").toString()));

        List<ProDataEntity> dataList = baseMapper.execProDataNb(params);
        //从第几条数据开始
        Integer firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        Integer lastIndex = currPage * pageSize;

        lastIndex = lastIndex > dataList.size() ? dataList.size() : lastIndex;

        return new PageUtils(dataList.subList(firstIndex, lastIndex),dataList.size(),pageSize,currPage);
    }


}
